package leetcode.singles;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @Author: Liu Yue
 * @Descripition:
 * @Date; Create in 2020/2/27 8:38
 **/
public class RegisterSingleTest {
    public static void main(String[] args) {
        RegisterSingle instance2 = RegisterSingle.getInstance();
        RegisterSingle instance3 = RegisterSingle.getInstance();
        instance2.setData(new Object());
        instance3.setData(new Object());
        Object instance = RegisterSingle.INSTANCE.getInstance();
        Object instance1 = RegisterSingle.INSTANCE.getInstance();
        System.out.println(instance2 == instance3 );


        Class clazz = RegisterSingle.class;

        Constructor declaredConstructor =
                null;
        try {
            declaredConstructor = clazz.getDeclaredConstructor(String.class,int.class);
            declaredConstructor.setAccessible(true);
            Object o = declaredConstructor.newInstance();
            System.out.println(o);

        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

    }
}
